<template>
	<div class="common_tabs_container">
		<el-tabs type="card" class="custom_top" v-model="activeName">
			<el-tab-pane label="待审核" name="1"></el-tab-pane>
			<el-tab-pane label="已审核" name="2"></el-tab-pane>
		</el-tabs>
		<sw-common-frame :loading="loading">
			<el-table slot="table" size="medium" :data="tableData" height="100%">
				<el-table-column label="序号" type="index" width="48" align="center" />
				<el-table-column label="下载状态" width="90" :formatter="returnDownloadStatus" />
				<el-table-column label="资源名称" prop="pcName" min-width="240" />
				<el-table-column label="描述" prop="content" min-width="240" />
				<el-table-column label="创建人" prop="createName" min-width="120" />
				<el-table-column label="创建时间" prop="createTime" min-width="160" />
				<el-table-column label="操作" width="160" v-if="activeName === '1'">
					<template slot-scope="{ row }">
						<el-button size="medium" type="text" @click="handleLookData(row)">预览</el-button>
						<el-button size="medium" type="text" @click="handleAuditData(row)">审核</el-button>
						<el-button size="medium" type="text" @click="handleDeleteData(row)">彻底删除</el-button>
					</template>
				</el-table-column>
			</el-table>
			<template slot="page">
				<sw-pagination :total="dataCount" :page.sync="queryData.page" :limit.sync="queryData.limit" @change="queryTableData()"></sw-pagination>
			</template>
		</sw-common-frame>
		<audit-dialog v-model="auditDialog" :data-id="dataId"></audit-dialog>
	</div>
</template>

<script>
import auditDialog from './audit';
import { mapGetters } from 'vuex';
import listMixins from '@/mixins/listMixins';
import { getResInformPageList } from '@/api/data/tbNetReport';
export default {
	mixins: [listMixins],
	components: { auditDialog },
	data() {
		return {
			activeName: '1',
			dataId: '',
			auditDialog: false
		};
	},
	computed: {
		...mapGetters(['userInfo']),
		listFunction() {
			return eval(getResInformPageList);
		},
		requestParams() {
			return { ...this.queryData, category: '2' };
		}
	},
	watch: {
		activeName: {
			handler(val) {
				this.queryData.page = 1;
				if (val === '1') {
					this.$set(this.queryData, 'auditStatus', '1');
				} else if (val === '2') {
					this.$set(this.queryData, 'auditStatus', '2,3,4');
				}
				this.queryTableData();
			},
			immediate: true
		}
	},
	methods: {
		//返回下载状态
		returnDownloadStatus(data) {
			let text = '';
			let attrs = { size: 'medium', disableTransitions: true };
			if (data.auditStatus === '1') {
				text = '待审核';
			} else if (data.auditStatus === '2') {
				text = '未通过';
				attrs['type'] = 'danger';
			} else if (data.auditStatus === '3') {
				text = '已通过';
				attrs['type'] = 'success';
			} else if (data.auditStatus === '4') {
				text = '自动通过';
				attrs['type'] = 'success';
			}
			return this.$createElement('ElTag', { attrs }, text);
		},

		//预览资源
		handleLookData(data) {
			this.$router.push({ path: `/data/resource/${data.pcId}` });
		},

		//审核按钮
		handleAuditData(data) {
			this.dataId = data.id;
			this.auditDialog = true;
		},

		//删除下载
		handleDeleteData(data) {
			console.log(data.id);
		}
	}
};
</script>
